

//
//  ComNoteLIstCell.m
//  DogeLegs
//
//  Created by 宋华 on 2017/8/20.
//  Copyright © 2017年 宋华. All rights reserved.
//

#import "ComNoteLIstCell.h"
#import "ComNoteImageScrollview.h"

@interface ComNoteLIstCell () <UIScrollViewDelegate> {

}
@property (weak, nonatomic) IBOutlet UIImageView *userLogoImageview;

@property (weak, nonatomic) IBOutlet UILabel *userNameLabel;

@property (weak, nonatomic) IBOutlet UILabel *addNoteDateLabel;

@property (weak, nonatomic) IBOutlet UILabel *notePriceLabel;

@property (weak, nonatomic) IBOutlet UILabel *noteTitleLabel;

@property (weak, nonatomic) IBOutlet UILabel *noteContentLabel;

@property (weak, nonatomic) IBOutlet ComNoteImageScrollview *noteItemViews;

@property (weak, nonatomic) IBOutlet UILabel *likeCountLabel;

@property (weak, nonatomic) IBOutlet UILabel *discussionCountLabel;

- (IBAction)reverseLike:(id)sender;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *itemsViewWidth;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *itemsViewHeight;

@property (nonatomic,strong)NoteMode *noteMode;

@end

@implementation ComNoteLIstCell

- (void)awakeFromNib {
    [super awakeFromNib];
    setCornerRadius(self.userLogoImageview, 15);
    self.noteItemViews.delegate = self;
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)cellWillDisplay:(NoteMode *)mode {
    self.noteMode = mode;
    //暂时这么写,图片要替换
    [self.userLogoImageview sd_setImageWithURL:[NSURL URLWithString:mode.userMode.headPortraitUrl] placeholderImage:[UIImage imageNamed:@"photo"]];
    [self.userNameLabel setText:mode.userMode.userName];
    [self.addNoteDateLabel setText:mode.noteDateStr];
    [self.notePriceLabel setText:mode.doallorPrice];
    [self.noteTitleLabel setText:mode.noteTitle];
    [self.noteContentLabel setText:mode.noteContent];
    if (mode.noteImages.count == 0) {
        self.itemsViewWidth.constant = 0;
        self.itemsViewHeight.constant = 0;
    } else {
        self.noteItemViews.noteImages =  mode.noteImages;
//        [self.noteItemViews reloadItems:mode.noteImages topLeftPoint:CGPointMake(0, 0) isAddNote:NO];
//        if (mode.noteImages.count == 1) {
//            self.itemsViewHeight.constant = self.noteItemViews.totalWidth;
//
//            self.itemsViewHeight.constant = self.noteItemViews.totalHeight;
//
//        } else {
//            self.itemsViewHeight.constant = self.noteItemViews.totalHeight;
//        }
    }
    self.likeCountLabel.text = mode.likeCountStr;

    self.discussionCountLabel.text = mode.dicusCountStr;
    
    [self.noteItemViews setContentOffset:CGPointMake(self.noteMode.imageScrollOffsetX, 0) animated:YES];
}

#pragma mark - 高度
+ (CGFloat) comNoteCellHeight:(NoteMode *)mode {
    CGFloat totalHeight = 132;//固定高度
    //图片高度
    if (mode.noteImages.count > 0) {
        totalHeight += kImageItemWidth;
    }
    //title高度
    CGFloat w = kScreenWidth - 30;
   totalHeight += [mode.noteTitle sizeWithFont:[UIFont systemFontOfSize:14] maxSize:CGSizeMake(w, 100000)].height;
    //内容高度
    totalHeight += [mode.noteContent sizeWithFont:[UIFont systemFontOfSize:12] maxSize:CGSizeMake(w, 100000)].height;
    return totalHeight;
}

#pragma mark delegate - UIScrollViewDelegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    
    self.noteMode.imageScrollOffsetX = scrollView.contentOffset.x;
    
}
#pragma mark - action事件
- (IBAction)reverseLike:(id)sender {
    if (self.revLikeBlock) {
        self.revLikeBlock();
    }
}
@end
